package com.hntxk.cqzd.flup.bizcheck;

import com.hntxk.core.framework.bizchk.BaseBizCheck;
import com.hntxk.cqzd.flup.entity.FlupFile;
import com.hntxk.cqzd.flup.entity.FlupInfo;
import com.hntxk.cqzd.flup.service.FlupInfoService;


import java.util.List;


/**
 * 数据字典check
 * 
 * @author huang.biquan
 * @date 2012-5-30 上午10:15:09
 */
public class FlupBizCheck extends BaseBizCheck<FlupInfo> {
	private  FlupInfoService flupInfoService;
	/**
	 * contruct;
	 */
	public FlupBizCheck(FlupInfoService flupInfoService) {
		super();
		this.flupInfoService = flupInfoService;
	}
	
	@Override
	public void addable(FlupInfo t){
		
		// 判断是否要进行check;
		if (!isNeedBizCheck()) {
			return;
		}
		//编号不重复
		FlupInfo temp = new FlupInfo();
		temp.setFlupId(t.getFlupId());
		List<FlupInfo> list = flupInfoService.query(temp);
		if (list.size()>0) {
			addError("随访id "+t.getFlupId()+" 已被使用,需要更换.");
		}
	}


	@Override
	public void deletable(FlupInfo t){
		// 判断是否要进行check;
		if (!isNeedBizCheck()) {
			return;
		}
		FlupFile flupFile=new FlupFile();
		flupFile.setFlupId(t.getFlupId());

		int count = flupInfoService.countFileInfoById(flupFile);
		if (count>0){
			t = flupInfoService.get(t.getFlupId());
			addError("随访记录:"+t.getFlupId()+",有 "+count+" 个文件.");
		}
	}


	@Override
	public void updatable(FlupInfo t){
		
		
	}
}
